
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 11/15/2014 09:52:14
-- Generated from EDMX file: C:\Users\Teerasak\Documents\Visual Studio 2012\Projects\ProductTransfer\NawaData\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [nawaDb];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[nawaDbModelStoreContainer].[vmsa140_product_basic]', 'U') IS NOT NULL
    DROP TABLE [nawaDbModelStoreContainer].[vmsa140_product_basic];
GO
IF OBJECT_ID(N'[dbo].[vmsa144_product_convunit]', 'U') IS NOT NULL
    DROP TABLE [dbo].[vmsa144_product_convunit];
GO
IF OBJECT_ID(N'[dbo].[vmsa160_movtype]', 'U') IS NOT NULL
    DROP TABLE [dbo].[vmsa160_movtype];
GO
IF OBJECT_ID(N'[dbo].[vmsa302_pipe_prodcate_product]', 'U') IS NOT NULL
    DROP TABLE [dbo].[vmsa302_pipe_prodcate_product];
GO
IF OBJECT_ID(N'[dbo].[vmsa551_saleorder_daily]', 'U') IS NOT NULL
    DROP TABLE [dbo].[vmsa551_saleorder_daily];
GO
IF OBJECT_ID(N'[nawaDbModelStoreContainer].[vmsa593_billdata_0280]', 'U') IS NOT NULL
    DROP TABLE [nawaDbModelStoreContainer].[vmsa593_billdata_0280];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'vmsa140_product_basic'
CREATE TABLE [dbo].[vmsa140_product_basic] (
    [mmatno] varchar(18)  NOT NULL,
    [mmateng] varchar(40)  NOT NULL,
    [mmatthai] varchar(40)  NOT NULL,
    [mmattype] varchar(4)  NOT NULL,
    [mmatgrp] varchar(9)  NOT NULL,
    [mbaseunit] varchar(3)  NOT NULL,
    [mprodh] varchar(18)  NOT NULL,
    [mprodhl1] varchar(2)  NULL,
    [mprodhl2] varchar(4)  NULL,
    [mprodhl3] varchar(7)  NULL,
    [mprodhl4] varchar(10)  NULL,
    [mprodhl5] varchar(14)  NULL,
    [moldmat] varchar(18)  NOT NULL,
    [meancode] varchar(13)  NOT NULL,
    [mmatmemo] varchar(18)  NULL,
    [mnetwgt] decimal(13,3)  NOT NULL,
    [mgrosswgt] decimal(13,3)  NOT NULL,
    [munitwgt] varchar(3)  NOT NULL,
    [mvolume] decimal(13,3)  NOT NULL,
    [munitvolume] varchar(3)  NULL,
    [msize] varchar(32)  NULL,
    [mmatgrppack] varchar(4)  NOT NULL,
    [mpauniten] varchar(10)  NOT NULL,
    [mbaseunitth] varchar(10)  NOT NULL,
    [mcreatedate] datetime  NOT NULL,
    [mchangedate] datetime  NOT NULL,
    [mflagdel] varchar(1)  NULL,
    [mrundate] datetime  NOT NULL
);
GO

-- Creating table 'vmsa144_product_convunit'
CREATE TABLE [dbo].[vmsa144_product_convunit] (
    [mmatno] varchar(18)  NOT NULL,
    [muomconvalue] decimal(13,0)  NOT NULL,
    [muom] varchar(3)  NOT NULL,
    [mbaseconvalue] decimal(13,0)  NOT NULL,
    [mbaseunit] varchar(3)  NOT NULL,
    [mrundate] datetime  NOT NULL
);
GO

-- Creating table 'vmsa160_movtype'
CREATE TABLE [dbo].[vmsa160_movtype] (
    [mmovtype] char(3)  NOT NULL,
    [mmovcate1] varchar(20)  NULL,
    [mmovcate2] varchar(20)  NULL,
    [mmovcate3] varchar(20)  NULL,
    [mmovsubcate] varchar(20)  NULL,
    [mmovcate1_display] varchar(20)  NULL,
    [mmovcate2_display] varchar(20)  NULL,
    [mmovcate3_display] varchar(20)  NULL,
    [mmovsubcate_display] varchar(20)  NULL,
    [mmovcate_flag] bit  NULL,
    [mstocktype] varchar(50)  NULL,
    [mreverse] varchar(50)  NULL,
    [mmovtype_desc] varchar(100)  NULL,
    [mmovtype_desc_th] varchar(100)  NULL,
    [useflag] bit  NULL,
    [remark] varchar(50)  NULL,
    [storing_status] varchar(3)  NULL,
    [sap_iflag_fg] char(1)  NULL,
    [sap_iflag_rm] char(1)  NULL
);
GO

-- Creating table 'vmsa302_pipe_prodcate_product'
CREATE TABLE [dbo].[vmsa302_pipe_prodcate_product] (
    [mprodsubcate] varchar(25)  NOT NULL,
    [mprodh] char(18)  NULL,
    [mmatno] varchar(18)  NOT NULL,
    [mmatthai] varchar(40)  NOT NULL,
    [mpackbox] varchar(50)  NULL,
    [mpackqty] int  NULL,
    [mupdatedate] datetime  NOT NULL,
    [remark] varchar(30)  NULL,
    [refno] varchar(5)  NULL,
    [mrank1] int  NULL,
    [mprodtype] nvarchar(3)  NULL,
    [mflagdel] varchar(1)  NULL
);
GO

-- Creating table 'vmsa551_saleorder_daily'
CREATE TABLE [dbo].[vmsa551_saleorder_daily] (
    [mordno] char(10)  NOT NULL,
    [morditemno] char(6)  NOT NULL,
    [msoldto] char(10)  NULL,
    [mshipto] char(10)  NULL,
    [mshipname1] varchar(40)  NULL,
    [mshipname2] varchar(40)  NULL,
    [mstreet] varchar(60)  NULL,
    [mcity] varchar(40)  NULL,
    [mpono] varchar(35)  NULL,
    [mquotation] char(10)  NULL,
    [mquodate] datetime  NULL,
    [mdlvblock] varchar(2)  NULL,
    [mpayterm] char(4)  NULL,
    [mincoterm] char(3)  NULL,
    [mincoterm2] varchar(28)  NULL,
    [msaledoctype] char(4)  NULL,
    [msaleorg] char(4)  NULL,
    [mdc] char(2)  NULL,
    [mdiv] char(2)  NULL,
    [msaleoff] char(4)  NULL,
    [msalegrp] char(3)  NULL,
    [morddate] datetime  NULL,
    [mordtime] varchar(8)  NULL,
    [mupdate] datetime  NULL,
    [mdrivername] varchar(72)  NULL,
    [mcrestat] char(1)  NULL,
    [mexchange] varchar(5)  NULL,
    [mexchangerate] decimal(9,5)  NULL,
    [mpodate] datetime  NULL,
    [mmatno] char(18)  NULL,
    [mactqty] decimal(13,3)  NULL,
    [mdlvqty] decimal(13,3)  NULL,
    [mordduedate] datetime  NULL,
    [mamount] decimal(13,2)  NULL,
    [mnetprice] decimal(13,2)  NULL,
    [mnetvalue] decimal(13,2)  NULL,
    [mzzd0] decimal(13,2)  NULL,
    [mzzd0amt] decimal(13,2)  NULL,
    [mzzd1] decimal(13,2)  NULL,
    [mzzd1amt] decimal(13,2)  NULL,
    [mzzd2] decimal(13,2)  NULL,
    [mzzd2amt] decimal(13,2)  NULL,
    [mzzd3] decimal(13,2)  NULL,
    [mzzd3amt] decimal(13,2)  NULL,
    [mzzd4] decimal(13,2)  NULL,
    [mzzd4amt] decimal(13,2)  NULL,
    [mzzd6] decimal(13,2)  NULL,
    [mzzd6amt] decimal(13,2)  NULL,
    [mzzdl] decimal(13,2)  NULL,
    [mzzdlamt] decimal(13,2)  NULL,
    [mzzdm] decimal(13,2)  NULL,
    [mzzdmamt] decimal(13,2)  NULL,
    [mzzdo] decimal(13,2)  NULL,
    [mzzdoamt] decimal(13,2)  NULL,
    [mfilldate] datetime  NULL,
    [mroute] char(6)  NULL,
    [mcruser] varchar(12)  NULL,
    [mshippoint] char(4)  NULL,
    [mplant] char(4)  NULL,
    [mfirmqty] decimal(13,3)  NULL,
    [mstatus] varchar(2)  NULL,
    [mrundate] datetime  NULL
);
GO

-- Creating table 'vmsa593_billdata_0280'
CREATE TABLE [dbo].[vmsa593_billdata_0280] (
    [mbillno] char(10)  NOT NULL,
    [mbilltype] char(4)  NOT NULL,
    [mbillitemno] char(6)  NOT NULL,
    [mdoccurrency] varchar(5)  NOT NULL,
    [msaleorg] char(4)  NOT NULL,
    [mdc] char(2)  NOT NULL,
    [mbilldate] datetime  NOT NULL,
    [mpricegrp] char(2)  NOT NULL,
    [mcustgrp] char(2)  NULL,
    [mdistrict] char(6)  NULL,
    [mincoterm1] char(3)  NOT NULL,
    [mincoterm2] varchar(28)  NULL,
    [mpayterm] char(4)  NOT NULL,
    [mdestcountry] varchar(3)  NOT NULL,
    [mcompcode] char(4)  NOT NULL,
    [mbillnetamt] decimal(15,2)  NOT NULL,
    [mlocalcurrency] varchar(5)  NOT NULL,
    [massignmentno] varchar(18)  NULL,
    [mbilltaxamt] decimal(13,2)  NOT NULL,
    [mcancelbillno] varchar(10)  NULL,
    [mpayer] char(10)  NOT NULL,
    [msoldto] char(10)  NOT NULL,
    [mbillto] char(10)  NOT NULL,
    [mbillcreatedate] datetime  NOT NULL,
    [mbillchangedate] datetime  NOT NULL,
    [mbillqty] decimal(13,3)  NOT NULL,
    [msaleunit] varchar(3)  NOT NULL,
    [mpricingdate] datetime  NOT NULL,
    [mnetamt] decimal(15,2)  NOT NULL,
    [mrefdocno] char(10)  NOT NULL,
    [mrefitemno] char(6)  NOT NULL,
    [msaledocno] char(10)  NOT NULL,
    [msaleitemno] char(6)  NOT NULL,
    [mmatno] varchar(18)  NOT NULL,
    [mmatthai] varchar(40)  NOT NULL,
    [mmatgroup] varchar(9)  NOT NULL,
    [mprodh] char(18)  NOT NULL,
    [mshippoint] char(4)  NOT NULL,
    [mplant] char(4)  NOT NULL,
    [mdepartcountry] varchar(3)  NOT NULL,
    [msalegrp] char(3)  NULL,
    [msaleoff] char(4)  NULL,
    [mreturnitem] varchar(1)  NULL,
    [msloc] varchar(4)  NULL,
    [mtaxamt] decimal(13,2)  NOT NULL,
    [morderreason] varchar(3)  NULL,
    [mitemcate] char(4)  NOT NULL,
    [mshipto] char(10)  NOT NULL,
    [mshiproute] varchar(6)  NULL,
    [mbaseunit] varchar(3)  NOT NULL,
    [mbaseqty] decimal(13,3)  NOT NULL,
    [mordertype] char(4)  NULL,
    [mcustpono] varchar(35)  NULL,
    [mordcrdate_header] datetime  NULL,
    [mordcrtime_header] char(6)  NOT NULL,
    [mordcrdate_item] datetime  NULL,
    [mordcrtime_item] char(6)  NOT NULL,
    [musage] varchar(3)  NULL,
    [mquono] varchar(10)  NULL,
    [mquoitemno] char(6)  NULL,
    [mquopono] varchar(35)  NULL,
    [mgidate] datetime  NULL,
    [mdlvcreatedate] datetime  NULL,
    [mindkey] varchar(4)  NULL,
    [mnetwgt] decimal(13,3)  NOT NULL,
    [mtotalnetwgt] decimal(27,6)  NULL,
    [mexchangerateord] decimal(9,5)  NULL,
    [moutputtax] decimal(13,2)  NOT NULL,
    [mcost] decimal(13,2)  NOT NULL,
    [mwhtax] decimal(13,2)  NOT NULL,
    [mvc] decimal(13,2)  NOT NULL,
    [mnd] decimal(13,2)  NOT NULL,
    [msd] decimal(13,2)  NOT NULL,
    [mcd] decimal(13,2)  NOT NULL,
    [mad] decimal(13,2)  NOT NULL,
    [mothcharge] decimal(13,2)  NOT NULL,
    [mfreightdisc] decimal(13,2)  NOT NULL,
    [mdepotdisc] decimal(13,2)  NOT NULL,
    [mprojdisc] decimal(13,2)  NOT NULL,
    [msfreightdisc] decimal(13,2)  NOT NULL,
    [mcrdrdisc] decimal(13,2)  NOT NULL,
    [mfreight] decimal(13,2)  NOT NULL,
    [mdownpay] decimal(13,2)  NOT NULL,
    [minsurance] decimal(13,2)  NOT NULL,
    [mfocadjust] decimal(13,2)  NOT NULL,
    [mlp] decimal(13,2)  NOT NULL,
    [mexpnetprice] decimal(13,2)  NOT NULL,
    [mpriceround] decimal(13,2)  NOT NULL,
    [mexpcomm] decimal(13,2)  NOT NULL,
    [mvat] decimal(13,2)  NOT NULL,
    [mlpintercom] decimal(13,2)  NOT NULL,
    [mndintercom] decimal(13,2)  NOT NULL,
    [mrundate] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [mmatno], [mmateng], [mmatthai], [mmattype], [mmatgrp], [mbaseunit], [mprodh], [moldmat], [meancode], [mnetwgt], [mgrosswgt], [munitwgt], [mvolume], [mmatgrppack], [mpauniten], [mbaseunitth], [mcreatedate], [mchangedate], [mrundate] in table 'vmsa140_product_basic'
ALTER TABLE [dbo].[vmsa140_product_basic]
ADD CONSTRAINT [PK_vmsa140_product_basic]
    PRIMARY KEY CLUSTERED ([mmatno], [mmateng], [mmatthai], [mmattype], [mmatgrp], [mbaseunit], [mprodh], [moldmat], [meancode], [mnetwgt], [mgrosswgt], [munitwgt], [mvolume], [mmatgrppack], [mpauniten], [mbaseunitth], [mcreatedate], [mchangedate], [mrundate] ASC);
GO

-- Creating primary key on [mmatno], [muomconvalue], [muom], [mbaseconvalue], [mbaseunit], [mrundate] in table 'vmsa144_product_convunit'
ALTER TABLE [dbo].[vmsa144_product_convunit]
ADD CONSTRAINT [PK_vmsa144_product_convunit]
    PRIMARY KEY CLUSTERED ([mmatno], [muomconvalue], [muom], [mbaseconvalue], [mbaseunit], [mrundate] ASC);
GO

-- Creating primary key on [mmovtype] in table 'vmsa160_movtype'
ALTER TABLE [dbo].[vmsa160_movtype]
ADD CONSTRAINT [PK_vmsa160_movtype]
    PRIMARY KEY CLUSTERED ([mmovtype] ASC);
GO

-- Creating primary key on [mprodsubcate], [mmatno], [mmatthai], [mupdatedate] in table 'vmsa302_pipe_prodcate_product'
ALTER TABLE [dbo].[vmsa302_pipe_prodcate_product]
ADD CONSTRAINT [PK_vmsa302_pipe_prodcate_product]
    PRIMARY KEY CLUSTERED ([mprodsubcate], [mmatno], [mmatthai], [mupdatedate] ASC);
GO

-- Creating primary key on [mordno], [morditemno] in table 'vmsa551_saleorder_daily'
ALTER TABLE [dbo].[vmsa551_saleorder_daily]
ADD CONSTRAINT [PK_vmsa551_saleorder_daily]
    PRIMARY KEY CLUSTERED ([mordno], [morditemno] ASC);
GO

-- Creating primary key on [mbillno], [mbilltype], [mbillitemno], [mdoccurrency], [msaleorg], [mdc], [mbilldate], [mpricegrp], [mincoterm1], [mpayterm], [mdestcountry], [mcompcode], [mbillnetamt], [mlocalcurrency], [mbilltaxamt], [mpayer], [msoldto], [mbillto], [mbillcreatedate], [mbillchangedate], [mbillqty], [msaleunit], [mpricingdate], [mnetamt], [mrefdocno], [mrefitemno], [msaledocno], [msaleitemno], [mmatno], [mmatthai], [mmatgroup], [mprodh], [mshippoint], [mplant], [mdepartcountry], [mtaxamt], [mitemcate], [mshipto], [mbaseunit], [mbaseqty], [mordcrtime_header], [mordcrtime_item], [mnetwgt], [moutputtax], [mcost], [mwhtax], [mvc], [mnd], [msd], [mcd], [mad], [mothcharge], [mfreightdisc], [mdepotdisc], [mprojdisc], [msfreightdisc], [mcrdrdisc], [mfreight], [mdownpay], [minsurance], [mfocadjust], [mlp], [mexpnetprice], [mpriceround], [mexpcomm], [mvat], [mlpintercom], [mndintercom], [mrundate] in table 'vmsa593_billdata_0280'
ALTER TABLE [dbo].[vmsa593_billdata_0280]
ADD CONSTRAINT [PK_vmsa593_billdata_0280]
    PRIMARY KEY CLUSTERED ([mbillno], [mbilltype], [mbillitemno], [mdoccurrency], [msaleorg], [mdc], [mbilldate], [mpricegrp], [mincoterm1], [mpayterm], [mdestcountry], [mcompcode], [mbillnetamt], [mlocalcurrency], [mbilltaxamt], [mpayer], [msoldto], [mbillto], [mbillcreatedate], [mbillchangedate], [mbillqty], [msaleunit], [mpricingdate], [mnetamt], [mrefdocno], [mrefitemno], [msaledocno], [msaleitemno], [mmatno], [mmatthai], [mmatgroup], [mprodh], [mshippoint], [mplant], [mdepartcountry], [mtaxamt], [mitemcate], [mshipto], [mbaseunit], [mbaseqty], [mordcrtime_header], [mordcrtime_item], [mnetwgt], [moutputtax], [mcost], [mwhtax], [mvc], [mnd], [msd], [mcd], [mad], [mothcharge], [mfreightdisc], [mdepotdisc], [mprojdisc], [msfreightdisc], [mcrdrdisc], [mfreight], [mdownpay], [minsurance], [mfocadjust], [mlp], [mexpnetprice], [mpriceround], [mexpcomm], [mvat], [mlpintercom], [mndintercom], [mrundate] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------